﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;

public partial class imgGrab : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
    try
        {

            DataSet ds = new DataSet();
            System.Data.SqlClient.SqlDataAdapter da = new System.Data.SqlClient.SqlDataAdapter();
            
            byte[] arrContent ;

            DataRow dr ;

            string  strSql ;

            strSql = "Select * from imgTable Where imgId= " + Request.QueryString["ID"];


            String connString = @"Data Source=.\SQLEXPRESS;AttachDbFilename='C:\Ashwin\SampleCode\AjaxJQueryMulFileUpload\App_Data\imgDB.mdf';Integrated Security=True;User Instance=True";

            da = new System.Data.SqlClient.SqlDataAdapter(strSql, connString);

            da.Fill(ds);

            dr = ds.Tables[0].Rows[0];

            arrContent = (byte[])dr["imgData"];


            String conType = dr["imgType"].ToString();

            Response.ContentType = conType;

            Response.OutputStream.Write(arrContent, 0, Convert.ToInt32(dr["imgLength"]));

            Response.End();
        }
        catch (Exception ex)
        {
            string err =  ex.Message;
        }
    }
}
